package com.ang.springboot.consumer.topic;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class TopicConsumer {
    /**
     * 2个消费者监听topicQueueMan，会轮询消费
     * @param msg
     */
    @RabbitListener(queuesToDeclare = @Queue(value = "topicQueueMan"))
    public void getMessage1(Map msg){
        //topicQueueMan绑定交换机的key为：topic.man，只能接收到routKey为topic.man的消息
        System.out.println("队列：topicQueueMan；绑定路由键为：topic.man，消息：" + JSON.toJSONString(msg) + "，处理者：getMessage1");
    }
    @RabbitListener(queues = "topicQueueMan")
    public void getMessage1_1(Map msg){
        System.out.println("队列：topicQueueMan；绑定路由键为：topic.man，消息：" + JSON.toJSONString(msg) + "，处理者：getMessage1_1");
    }

    @RabbitListener(queuesToDeclare = @Queue(value = "topicQueueWoman"))
    public void getMessage2(Map msg){
        //topicQueueWoman绑定交换机的key为：topic.#，能接收到routKey为topic.man和topic.woman的消息
        System.out.println("队列：topicQueueWoman；绑定路由键为：topic.#，消息：" + JSON.toJSONString(msg));
    }
}
